<template>
  <div>
    <el-button @click="dialogVisible = true">在地图上搜索</el-button>
    <el-dialog title="选择地点" :visible.sync="dialogVisible" width="50%" :close-on-click-modal="false" :append-to-body="true">
      <el-input prefix-icon="el-icon-search" placeholder="输入关键字搜索" style="margin-bottom: 10px" v-model="keyword">
      </el-input>
      <baidu-map center="宜昌">
        <bm-view class="map"></bm-view>
        <bm-local-search :keyword="keyword" :auto-viewport="true" :location="location" @infohtmlset="handleInfoSet"></bm-local-search>
      </baidu-map>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="getAddressInfo">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { BaiduMap } from "vue-baidu-map/components";

export default {
  name: "MapButton",
  components: { BaiduMap },
  data() {
    return {
      dialogVisible: false,
      location: '宜昌',
      keyword: '',
      position: {}
    }
  },
  methods: {
    handleInfoSet(poi) {
      this.position = poi
    },
    getAddressInfo() {
      this.$emit('getAddressInfo', this.position)
      this.dialogVisible = false
    }
  }
}
</script>

<style lang="scss" scoped>
.map {
  width: 100%;
  height: 400px;
}
</style>
